package com.example.normal.controller;

import com.example.base.domain.PageVo;
import com.example.base.domain.TableDataInfo;
import com.example.base.result.AjaxResult;
import com.example.normal.entity.Student;
import com.example.normal.mapper.StudentMapper;
import com.example.normal.service.IStudentService;
import com.example.utils.CvtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private IStudentService studentService;

    /**
     * 测试路径变量（数组）怎么接收参数
     * @author wanghongyu02
     * @date 2024-08-09 14:37
     * @param ids
     * @return com.example.base.result.AjaxResult
     */
    @PostMapping("/testPathVariable/{ids}")
    public AjaxResult testPathVariable(@PathVariable Integer[] ids) {
        return AjaxResult.success(ids);
    }

    /**
     * 测试MybatisPlus的分页Page+自定义Mapper方法
     *
     * @author wanghongyu02
     * @date 2024-08-09 14:52
     */
    @PostMapping("/testStudentPage")
    public TableDataInfo testStudentPage(@RequestBody Student student, PageVo pageVo) {
        return CvtUtils.cvtIPageToTableDataInfo(studentService.testStudentPage(student,pageVo));
    }

    /**
     * JSONObject返回出现下划线的问题
     * @author wanghongyu02
     * @date 2024-09-12 11:05
     * @param student
     * @return com.example.base.result.AjaxResult
     */
    @PostMapping("/testJSONObject")
    public AjaxResult testJSONObject(@RequestBody Student student) {
        return AjaxResult.success(studentService.testJSONObject(student));
    }

}
